home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / readir < prev    next >
Internet Message Format  |  1995-03-31  |  3KB

  1. Path: funic!fuug!sunic!uupsi!rpi!zaphod.mps.ohio-state.edu!think.com!linus!agate!shelby!msi.umn.edu!noc.MR.NET!gacvx2.gac.edu!hhdist
  2. From: erikmb@cd.chalmers.se (Erik Bryntse)
  3. Newsgroups: comp.sys.handhelds
  4. Subject: Test program that reads the IR input of HP48
  5. Message-ID: <9102130722.AA23435@hpysolw.tky.hp.com>
  6. Date: 3 Dec 90 11:46:55 GMT
  7. Lines: 143
  8. Return-path: <zuka@hpysolw.tky.hp.com>
  9. To: zuka@hpysolw.tky.hp.com
  10. To: handhelds@gac.edu
  11.  
  12.  
  13. Hello!
  14.  
  15. Since there are many people that are interested in having their 48's 
  16. as learning remote controls, I am posting a little test program I 
  17. wrote some weeks ago.
  18.  
  19. It reads the IR input diode, and times each period (at the low-high 
  20. transition). The result is returned as a string.
  21.  
  22. This is only intended to help if someone out there is struggling to 
  23. make a remote control program for the 48, so I only include the source 
  24. code. It is not very well commented (remember it's a test program...).
  25.  
  26. Hope this helps someone!
  27.  
  28. Erik Bryntse
  29.  
  30. erikmb@cd.chalmers.se
  31.  
  32.  
  33. ; ---- source code begins here ----
  34.  
  35. SaveR:=#679B
  36. LoadR:=#67D2    
  37. DispOff:=#1BBD
  38. DispOn:=#1B8F
  39.  
  40.  
  41. ; Test program that reads the IR-diode
  42. ; Written by Erik Bryntse
  43. ; Returns 1: "string" that contains 3 nibbles per period time
  44. ; Parts taken from INPRT by William C Wickes
  45.  
  46.  
  47.     call.a        SaveR        ; save RPL regs
  48.     call.a        #613E
  49.     clrb        15,ST
  50.     call.a        #6806        ; space bw RSTK & TOS -> C
  51.     move.a        c,a
  52.     move.p5        #10F,c
  53.     subn.a        a,c        ; C := space - #200
  54.     brcs        OutOfMem    ; If not enough exit
  55.  
  56.     move.w        c,r1        ; Save away in R1
  57.     call.a        #1115        ; toggles b 0 of #10E
  58.     intoff
  59.     call.a        DispOff
  60.     move.w        r1,c        ; Alloc all mem - #200 nibs
  61.     srb.a        c        ; in bytes!
  62.     call.a        #5B79        ; alloc C bytes string -> D0
  63.     move.w        r1,c
  64.     swap.a        a,d0
  65.     move.a        a,d0
  66.     add.a        c,a
  67.     move.w        a,r1        ; R1 highest allowed addr
  68.     clr.w        c
  69.     move.w        c,r4        ; R4 := 0
  70.     move.1        4,p
  71.     move.p1        #6,c        ; C := #60000
  72.     move.1        0,p
  73.     brcc        Begin        ; If alloc OK start prog
  74.     
  75. OutOfMem:
  76.     
  77.     call.a        #10E5
  78.     jump.a        #65AA        ; load regs, Out Of Mem!
  79.  
  80. ; Not out of memory error
  81.  
  82. Begin:    call.3        MainProc
  83.     call.a        #16671
  84.     move.5        #10B,d1
  85.     move.b        @d1,c
  86.     clrb        #5,c
  87.     move.b        c,@d1        ; clrb 5 of #10B
  88.     call.a        DispOn
  89.     call.a        #10E5
  90.     move.w        r0,a
  91.     call.a        #54266
  92.     move.a        @d0,a
  93.     add.a        5,d0
  94.     jump        @a        ; bye bye
  95.     
  96. ;========================================================
  97.  
  98. MainProc:
  99.  
  100.     call.3        Wait1st        ; Wait until IR toggle or timeout
  101.     retcs                ; Timeout: return
  102.  
  103. OneMor:    
  104.  
  105.     move.x        a,@d0        ; Store period time in string (3 nibs)
  106.     add.a        3,d0
  107.     swap.a        a,d0
  108.     move.a        a,d0
  109.     move.a        r1,c
  110.     retle.a        c,a
  111.     clr.a        a
  112.     call.3        WaitL        ; Time one more pulse
  113.     brcc        OneMor
  114.  
  115.     retclrc                ; Timeout
  116.  
  117.  
  118. ; Wait until first IR pulse is received
  119.  
  120. Wait1st:
  121.  
  122.     clr.w        a
  123.     move.p5        #20000,c    ; Timeout counter
  124.     move.5        #0011A,d1
  125. NoIR:    dec.a        c
  126.     brcs        TimeOut
  127.     move.s        @d1,c
  128.     add.s        c,c
  129.     brcc        NoIR        ; Wait until first IR pulse recvd
  130.  
  131. ; Wait until IR goes low
  132.  
  133. WaitL:    inc.x        a
  134.     retcs
  135.     move.s        @d1,c
  136.     add.s        c,c
  137.     brcs        WaitL        ; Wait until bit 3 of 11A low
  138.  
  139. ; Wait until IR goes high again
  140.  
  141. WaitH:    inc.x        a
  142.     retcs
  143.     move.s        @d1,c
  144.     add.s        c,c
  145.     brcc        WaitH        ; Wait until bit 3 of 11A high
  146.     retclrc
  147.  
  148. TimeOut:
  149.     
  150.     pop.a        c
  151.     retsetc
  152.  
  153. ; ---- souce code ends here ----    
  154. ----------
  155.